package com.chain.qs.modules.biz.web;

import com.chain.qs.common.utils.StringUtils;
import com.chain.qs.common.web.BaseController;
import com.chain.qs.modules.biz.entity.OfficeBiz;
import com.chain.qs.modules.biz.entity.StationGroup;
import com.chain.qs.modules.biz.service.StationGroupService;
import com.chain.qs.modules.sys.service.OfficeService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by fgx on 2016/10/18.
 */
public abstract class SeniorController extends BaseController {

    @Resource
    OfficeService officeService;
    @Resource
    StationGroupService sgroupService;
    List<StationGroup> sglist;

    @ModelAttribute("officebiz")
    public OfficeBiz getOffice(String officeId) {
        OfficeBiz officebiz = new OfficeBiz();
        if (StringUtils.isNotBlank(officeId)) {
            officebiz.setId(officeService.get(officeId).getId());
            officebiz.setName(officeService.get(officeId).getName());
            officebiz.setCode(officeService.get(officeId).getCode());
            if (officebiz.getId() != null) {
                sglist = sgroupService.findListByOfficeId(officebiz.getId());
//                model.addAttribute("sglist", sglist);
            }
        }
        return officebiz;
    }

    @RequestMapping(value = "sgroupSelect", method = RequestMethod.POST)
public String sgroupSelect(HttpServletResponse response) {
    return renderString(response, sglist);
}

}
